<?php
/**
 * 沿線・駅検索用関数<br />
 *
 * @package apamanshop
 * @author　SS永田
 * @copyright　
 */
class Rstobi_Model_EnsenekiSearch extends Rstobi_Model_Base
{
    /**
     * 駅検索用From句取得
     * 
	 * @access	public
	 * @param   array
	 * @param	array ※参照渡し
	 * @return  string
     */
	public function getFromForEkisearch($params ,&$db_params)
	{
		//駅CDをカンマ区切りにする
		$strStCd='';
		for ($i = 0; $i < count($params['StCd']); $i++)
		{
			// カンマの取得
			$strComma = $this->_model_rstobi_common->getPause($i,",");
			$db_params['strStCd_'.$i] = $params['StCd'][$i];
			
			$strStCd .= $strComma.' :strStCd_'.$i.' ';
		}
		
		$strFrom  = ' from';
		$strFrom .= ' (select';
		$strFrom .= '      M03_ENSEN_CD';
		$strFrom .= '     ,M03_EKI_CD';
		$strFrom .= '  from';
		$strFrom .= '      M03EKI';
		$strFrom .= '  where';
		$strFrom .= '      M03_RENRAKU_EKI_CD in (select /*+ index(M03 PKM03_EKI_CD) */';
		$strFrom .= '                                 M03_RENRAKU_EKI_CD';
		$strFrom .= '                             from';
		$strFrom .= '                                 M03EKI M03';
		$strFrom .= '                             where';
		$strFrom .= '                                 M03_EKI_CD in ('.$strStCd.'))';
		$strFrom .= ' union';
		$strFrom .= ' select /*+ index(M03 PKM03_EKI_CD) */';
		$strFrom .= '     M03_ENSEN_CD';
		$strFrom .= '    ,M03_EKI_CD';
		$strFrom .= ' from';
		$strFrom .= '     M03EKI M03';
		$strFrom .= ' where';
		$strFrom .= '     M03_EKI_CD in ('.$strStCd.')) M03';
		$strFrom .= ' ,T03WEB_HEYA T03';
		
		return $strFrom;
	}
	
    /**
     * 駅検索用Where句取得
     * 
	 * @access	public
	 * @param   array
	 * @param	array ※参照渡し
	 * @return  string
     */
	public function getWhereForEkisearch($params ,&$db_params)
	{
		
		// 都道府県CDをカンマ区切りにする
		$strPrefCd='';
		for ($i = 0; $i < count($params['PrefCd']); $i++)
		{
			// カンマの取得
			$strComma = $this->_model_rstobi_common->getPause($i,",");
			$db_params['strPrefCd_'.$i] = $params['PrefCd'][$i];
			
			$strPrefCd .= $strComma.' :strPrefCd_'.$i.' ';
		}
		
		$strWhere  = ' where';
		
		// カンマ区切り都道府県CDをWhere句に結合
		$strWhere .= '  T03.T03_TODOUFUKEN_CD in ('.$strPrefCd.')';
		
		// 沿線・駅CD
		$strWhere .= ' AND (   M03.M03_EKI_CD = T03.T03_EKI_CD01';
		$strWhere .= '      OR M03.M03_EKI_CD = T03.T03_EKI_CD02';
		$strWhere .= '      OR M03.M03_EKI_CD = T03.T03_EKI_CD03)';
		
		return $strWhere;
	}
	
    /**
     * 沿線検索用From句取得
     * 
	 * @access	public
	 * @return  string
     */
	public function getFromForEnsensearch($params ,&$db_params)
	{
		//駅CDをカンマ区切りにする
		$strRailCd='';
		for ($i = 0; $i < count($params['RailCd']); $i++)
		{
			// カンマの取得
			$strComma = $this->_model_rstobi_common->getPause($i,",");
			$db_params['strRailCd_'.$i] = $params['RailCd'][$i];
			
			$strRailCd .= $strComma.' :strRailCd_'.$i.' ';
		}
		
		$strFrom  = ' from';
		$strFrom .= ' (select';
		$strFrom .= '      M03_ENSEN_CD';
		$strFrom .= '     ,M03_EKI_CD';
		$strFrom .= '  from';
		$strFrom .= '      M03EKI';
		$strFrom .= '  where';
		$strFrom .= '      M03_RENRAKU_EKI_CD in (select /*+ index(M03 IDX_M03_EKI) */';
		$strFrom .= '                                 M03_RENRAKU_EKI_CD';
		$strFrom .= '                             from';
		$strFrom .= '                                 M03EKI M03';
		$strFrom .= '                             where';
		$strFrom .= '                                 M03_ENSEN_CD in ('.$strRailCd.'))';
		$strFrom .= ' union';
		$strFrom .= ' select /*+ index(M03 IDX_M03_EKI) */';
		$strFrom .= '     M03_ENSEN_CD';
		$strFrom .= '    ,M03_EKI_CD';
		$strFrom .= ' from';
		$strFrom .= '     M03EKI M03';
		$strFrom .= ' where';
		$strFrom .= '     M03_ENSEN_CD in ('.$strRailCd.')) M03';
		$strFrom .= ' ,T03WEB_HEYA T03';
		
		return $strFrom;
	}
	
    /**
     * 沿線検索用Where句取得
     * 
	 * @access	public
	 * @param   array
	 * @param	array ※参照渡し
	 * @return  string
     */
	public function getWhereForEnsensearch($params ,&$db_params)
	{
		$strWhere  = ' where';
		
		// 都道府県CDをカンマ区切りにする
		$strPrefCd='';
		for ($i = 0; $i < count($params['PrefCd']); $i++)
		{
			// カンマの取得
			$strComma = $this->_model_rstobi_common->getPause($i,",");
			$db_params['strPrefCd_'.$i] = $params['PrefCd'][$i];
			
			$strPrefCd .= $strComma.' :strPrefCd_'.$i.' ';
		}
		
		// カンマ区切り都道府県CDをWhere句に結合
		$strWhere .= ' T03.T03_TODOUFUKEN_CD in ('.$strPrefCd.')';
		
		// 沿線・駅CD
		$strWhere .= ' AND (   M03.M03_EKI_CD = T03.T03_EKI_CD01';
		$strWhere .= '      OR M03.M03_EKI_CD = T03.T03_EKI_CD02';
		$strWhere .= '      OR M03.M03_EKI_CD = T03.T03_EKI_CD03)';
		
		return $strWhere;
	}
}
?>